#include <memory>
#include "Channel.h"
#include "XnccType.h"
namespace xncc {
namespace msg {
    class FIFOQueue;
}
namespace sys {
    class EventFd;
}
namespace foundation {
    /// 线程间通信的channel  封装了一个eventfd
    class ThreadChannel final : public Channel
    {
      public:
        ThreadChannel(EventLoop* loop, std::shared_ptr<msg::FIFOQueue> msgQueue);

        ~ThreadChannel() override = default;

        ThreadChannel(const ThreadChannel&)             = delete;
        ThreadChannel(const ThreadChannel&&)            = delete;
        ThreadChannel& operator=(const ThreadChannel&)  = delete;
        ThreadChannel& operator=(const ThreadChannel&&) = delete;

        auto Type() -> ChannelType::value override { return ChannelType::THREAD_CHANNEL; }
        void handleRead() override;
        bool readfd();
        void HandleMessages(bool untilEmpty = false);

        types::queue_id_t queueId() const;

      private:
        bool HandleSingleMessage();

        std::shared_ptr<msg::FIFOQueue>     msgQueue_;
        std::shared_ptr<xncc::sys::EventFd> notifyfd_ = nullptr;
    };
}  // namespace foundation
}  // namespace xncc